<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE circuit>
<!--
	Example circuit.xml file for the controller portion of an application.
	Only the controller circuit has public access - the controller circuit
	contains all of the fuseactions that are used in links and form posts
	within your application.
-->
<circuit access="public" xmlns:cf="cf/">
	
<fuseaction name="welcome">	
		<set name="params.lastXDays" value="30" />
		<set name="params.maxEntries" value="25" />
		<do action="showEntries" />
	</fuseaction>

	<fuseaction name="day">
		<set name="params.byDay" value="#val(attributes.day)#"/>
		<set name="params.byMonth" value="#val(attributes.month)#"/>
		<set name="params.byYear" value="#val(attributes.year)#"/>
		<set name="month" value="#val(attributes.month)#"/>
		<set name="year" value="#val(attributes.year)#"/>
		<do action="v.day" contentvariable="leader" />
		<do action="showEntries" />
	</fuseaction>

	<fuseaction name="month">
		<set name="params.byMonth" value="#val(attributes.month)#"/>
		<set name="params.byYear" value="#val(attributes.year)#"/>
		<set name="month" value="#val(attributes.month)#"/>
		<set name="year" value="#val(attributes.year)#"/>
		<do action="v.month" contentvariable="leader" />
		<do action="showEntries" />
	</fuseaction>

	<fuseaction name="cat">
		<set name="params.byCat" value="#attributes.catid#"/>
		<do action="v.cat" contentvariable="leader" />
		<do action="showEntries" />
	</fuseaction>

	<fuseaction name="search">
		<set name="params.searchTerms" value="#htmlEditFormat(attributes.search)#"/>
		<do action="v.search" contentvariable="leader" />
		<do action="showEntries" />
	</fuseaction>

	<fuseaction name="entry">
		<set name="params.byEntry" value="#attributes.entry#"/>
		<do action="v.entry" contentvariable="leader" />
		<do action="showEntries" />
	</fuseaction>

	<fuseaction name="alias">
		<set name="params.byAlias" value="#attributes.alias#"/>
		<do action="v.entry" contentvariable="leader" />
		<do action="showEntries" />
	</fuseaction>
	
	<fuseaction name="login">
		<if condition="isUserInRole('admin')">
			<true>
				<do action="welcome" />
			</true>
			<false>
				<do action="v.showLogin" contentvariable="content" />
				<do action="showPage" />
			</false>
		</if>
	</fuseaction>
	
	<fuseaction name="logout">
		<if condition="getAuthUser() neq ''">
			<true>
				<do action="m.logout" />
			</true>
		</if>
		<do action="welcome" />
	</fuseaction>
	
	<fuseaction name="initialize">
		<if condition="isUserInRole('admin')">
			<true>
				<do action="m.initialize" />
				<do action="welcome" />
			</true>
			<false>
				<do action="login" />
			</false>
		</if>
	</fuseaction>
	
	<fuseaction name="commentPopup">
		<do action="m.loadComments" />
		<do action="v.showComments" />
	</fuseaction>
	
	<fuseaction name="deleteComment">
		<if condition="isUserInRole('admin')">
			<true>
				<do action="m.deleteComment" />
			</true>
		</if>
		<do action="m.loadComments" />
		<do action="v.showComments" />
	</fuseaction>
	
	<fuseaction name="addComment">
		<do action="m.saveNewComment" />
		<do action="v.showComments" />
	</fuseaction>
	
	<fuseaction name="editorPopup">
		<if condition="not isUserInRole('admin') or not structKeyExists(attributes,'id')">
			<true>
				<relocate url="#self#" />
			</true>
		</if>
		<do action="m.loadArticle" />
		<xfa name="action" value="blog.saveOrDeleteArticle" />
		<do action="v.editor" />
	</fuseaction>
	
	<fuseaction name="saveOrDeleteArticle">
		<if condition="not isUserInRole('admin')">
			<true>
				<relocate url="#self#" />
			</true>
		</if>
		<do action="m.saveOrDeleteArticle" />
		<if condition="hasErrors">
			<true>
				<do action="editorPopup" />
			</true>
			<false>
				<do action="v.reload" />
			</false>
		</if>
	</fuseaction>
	
	<fuseaction name="showEntries">
		<do action="m.getArticles" />
		<do action="v.main" contentvariable="content" />
		<do action="showPage" />
	</fuseaction>
	
	<fuseaction name="showPage">
		<do action="m.getCategories" />
		<if condition="isUserInRole('admin')">
			<true>
				<do action="v.admin" contentvariable="admin" />
			</true>
		</if>
		<do action="v.layout" />
	</fuseaction>
		
</circuit>
